<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>        
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>


    
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="/resource/js/jquery-3.2.1/jquery.js"></script>
</head>
<body>
	<button type="button" onclick="add()">添加</button>
	<table>
		<tr>
			<th>id</th>
			<th>姓名</th>
			<th>爱好</th>
			<th>编辑</th>
		</tr>
		<c:forEach items="${list}" var="stu">
			<tr>
				<td>${stu.id}</td>
				<td>${stu.name}</td>
				<td>
					<c:forEach items="${stu.favs}" var="fav" varStatus="index">
						${index.index>0?',':''} ${fav.name}
					</c:forEach>
				</td>
				<td><input type="button" value="编辑" onclick="update(${stu.id})">
				<input type="button" value="删除" onclick="del(${stu.id})">
				</td>
			</tr>
		</c:forEach>
	</table>
	
</body>

<script type="text/javascript">
	function add(){
		location.href="./toadd";
	}
	
	function update(id){
		location.href="./toupdate?id="+id;
	}
	
	function del(id){
		$.post("./del",{id:id},function(data){
			if(data=='ok'){
				alert("删除成功")
				history.go(0)
			}else{
				alert('删除失败')
			}
		})
	}
</script>
</html>